/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * vistaUsuario.java
 *
 * Created on 7/04/2011, 12:09:36 AM
 */

package jcpcotizaciones.vista;

/**
 *
 * @author FAMILIA MANOTAS
 */
import java.awt.Cursor;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import jcpcotizaciones.Control.ControlUsuario;
import jcpcotizaciones.Modelo.Usuario;
import javax.swing.JOptionPane;

public class vistaUsuario extends javax.swing.JFrame {

    /** Creates new form vistaUsuario */
    DefaultTableModel dtm = new DefaultTableModel();
    public vistaUsuario() {
        initComponents();
        listarUsuario();
    }
public void listarUsuario(){
        Usuario usu = new Usuario();
        try {
            dtm.setNumRows(0);
            ControlUsuario.listarUsuario();
            Iterator it = ControlUsuario.getUsuario().iterator();
            while (it.hasNext()) {
                usu = (Usuario) it.next();
                String[] fila = {usu.getCodigo(), usu.getCedula(), usu.getNombre(), usu.getCargo(), usu.getEmail()};
                dtm.addRow(fila);
            }
        DecimalFormat formateador = new DecimalFormat("000");
            if(usu.getCodigo()==null){
                tx_codigo.setText(formateador.format(1));
            }else{
                int contador_usu =Integer.parseInt(usu.getCodigo());
                contador_usu+=1;
                tx_codigo.setText(formateador.format(contador_usu));
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jd_eliminar = new javax.swing.JDialog();
        jPanel3 = new javax.swing.JPanel();
        imagen = new jcMousePanel.jcMousePanel();
        jLabel10 = new javax.swing.JLabel();
        bt_aceptar = new javax.swing.JButton();
        bt_cancelar = new javax.swing.JButton();
        pisoUsuario = new jcMousePanel.jcMousePanel();
        gestion = new jcMousePanel.jcMousePanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tx_codigo = new javax.swing.JTextField();
        tx_cedula = new javax.swing.JTextField();
        tx_nombre = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        cb_cargo = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        tx_reclave = new javax.swing.JPasswordField();
        jLabel21 = new javax.swing.JLabel();
        tx_email = new javax.swing.JTextField();
        tx_clave = new javax.swing.JPasswordField();
        jLabel1 = new javax.swing.JLabel();
        cb_buscar = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        tx_buscar = new javax.swing.JTextField();
        bt_buscar = new javax.swing.JButton();
        editar = new jcMousePanel.jcMousePanel();
        bt_guardar = new javax.swing.JButton();
        bt_modificar = new javax.swing.JButton();
        bt_eliminar = new javax.swing.JButton();
        bt_limpiar = new javax.swing.JButton();
        tabla = new jcMousePanel.jcMousePanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaUsuarios = new javax.swing.JTable(dtm);
        jcMousePanel1 = new jcMousePanel.jcMousePanel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jcpcotizaciones.JCPCOTIZACIONESApp.class).getContext().getResourceMap(vistaUsuario.class);
        jd_eliminar.setTitle(resourceMap.getString("jd_eliminar.title")); // NOI18N
        jd_eliminar.setModal(true);
        jd_eliminar.setName("jd_eliminar"); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        imagen.setFocusable(false);
        imagen.setIcon(resourceMap.getIcon("imagen.icon")); // NOI18N
        imagen.setName("imagen"); // NOI18N

        javax.swing.GroupLayout imagenLayout = new javax.swing.GroupLayout(imagen);
        imagen.setLayout(imagenLayout);
        imagenLayout.setHorizontalGroup(
            imagenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 69, Short.MAX_VALUE)
        );
        imagenLayout.setVerticalGroup(
            imagenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 67, Short.MAX_VALUE)
        );

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        bt_aceptar.setText(resourceMap.getString("bt_aceptar.text")); // NOI18N
        bt_aceptar.setToolTipText(resourceMap.getString("bt_aceptar.toolTipText")); // NOI18N
        bt_aceptar.setName("bt_aceptar"); // NOI18N
        bt_aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_aceptarActionPerformed(evt);
            }
        });

        bt_cancelar.setText(resourceMap.getString("bt_cancelar.text")); // NOI18N
        bt_cancelar.setToolTipText(resourceMap.getString("bt_cancelar.toolTipText")); // NOI18N
        bt_cancelar.setName("bt_cancelar"); // NOI18N
        bt_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imagen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(53, 53, 53)
                .addComponent(jLabel10)
                .addContainerGap(98, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(203, Short.MAX_VALUE)
                .addComponent(bt_aceptar)
                .addGap(18, 18, 18)
                .addComponent(bt_cancelar)
                .addGap(33, 33, 33))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(imagen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel10)))
                .addGap(25, 25, 25)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_aceptar)
                    .addComponent(bt_cancelar))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jd_eliminarLayout = new javax.swing.GroupLayout(jd_eliminar.getContentPane());
        jd_eliminar.getContentPane().setLayout(jd_eliminarLayout);
        jd_eliminarLayout.setHorizontalGroup(
            jd_eliminarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jd_eliminarLayout.setVerticalGroup(
            jd_eliminarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        pisoUsuario.setFocusable(false);
        pisoUsuario.setIcon(resourceMap.getIcon("pisoUsuario.icon")); // NOI18N
        pisoUsuario.setName("pisoUsuario"); // NOI18N

        gestion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("gestion.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("gestion.border.titleFont"), resourceMap.getColor("gestion.border.titleColor"))); // NOI18N
        gestion.setFocusable(false);
        gestion.setIcon(resourceMap.getIcon("gestion.icon")); // NOI18N
        gestion.setModo(2);
        gestion.setName("gestion"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        tx_codigo.setFont(resourceMap.getFont("tx_codigo.font")); // NOI18N
        tx_codigo.setText(resourceMap.getString("tx_codigo.text")); // NOI18N
        tx_codigo.setEnabled(false);
        tx_codigo.setName("tx_codigo"); // NOI18N

        tx_cedula.setText(resourceMap.getString("tx_cedula.text")); // NOI18N
        tx_cedula.setName("tx_cedula"); // NOI18N

        tx_nombre.setText(resourceMap.getString("tx_nombre.text")); // NOI18N
        tx_nombre.setName("tx_nombre"); // NOI18N
        tx_nombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_nombreActionPerformed(evt);
            }
        });
        tx_nombre.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_nombreFocusLost(evt);
            }
        });

        jLabel11.setName("jLabel11"); // NOI18N

        cb_cargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "VENDEDOR", "ADMINISTRADOR" }));
        cb_cargo.setName("cb_cargo"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        tx_reclave.setName("tx_reclave"); // NOI18N

        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        tx_email.setName("tx_email"); // NOI18N
        tx_email.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_emailFocusLost(evt);
            }
        });

        tx_clave.setName("tx_clave"); // NOI18N

        javax.swing.GroupLayout gestionLayout = new javax.swing.GroupLayout(gestion);
        gestion.setLayout(gestionLayout);
        gestionLayout.setHorizontalGroup(
            gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gestionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel11)
                    .addComponent(jLabel19)
                    .addComponent(jLabel20)
                    .addComponent(jLabel21))
                .addGap(18, 18, 18)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tx_nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                    .addComponent(tx_cedula, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                    .addComponent(cb_cargo, 0, 181, Short.MAX_VALUE)
                    .addComponent(tx_reclave, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                    .addComponent(tx_email, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                    .addComponent(tx_clave, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
                .addContainerGap())
        );
        gestionLayout.setVerticalGroup(
            gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gestionLayout.createSequentialGroup()
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tx_cedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tx_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cb_cargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(tx_clave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tx_reclave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel19)
                    .addComponent(tx_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(338, 338, 338)
                .addComponent(jLabel11)
                .addGap(57, 57, 57))
        );

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        cb_buscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "Cédula", "Nombre", "Cargo", " " }));
        cb_buscar.setName("cb_buscar"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        tx_buscar.setText(resourceMap.getString("tx_buscar.text")); // NOI18N
        tx_buscar.setName("tx_buscar"); // NOI18N
        tx_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_buscarActionPerformed(evt);
            }
        });

        bt_buscar.setIcon(resourceMap.getIcon("bt_buscar.icon")); // NOI18N
        bt_buscar.setText(resourceMap.getString("bt_buscar.text")); // NOI18N
        bt_buscar.setToolTipText(resourceMap.getString("bt_buscar.toolTipText")); // NOI18N
        bt_buscar.setName("bt_buscar"); // NOI18N
        bt_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_buscarActionPerformed(evt);
            }
        });

        editar.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("editar.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("editar.border.titleFont"), resourceMap.getColor("editar.border.titleColor"))); // NOI18N
        editar.setFocusable(false);
        editar.setIcon(resourceMap.getIcon("editar.icon")); // NOI18N
        editar.setModo(2);
        editar.setName("editar"); // NOI18N

        bt_guardar.setIcon(resourceMap.getIcon("bt_guardar.icon")); // NOI18N
        bt_guardar.setText(resourceMap.getString("bt_guardar.text")); // NOI18N
        bt_guardar.setToolTipText(resourceMap.getString("bt_guardar.toolTipText")); // NOI18N
        bt_guardar.setName("bt_guardar"); // NOI18N
        bt_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_guardarActionPerformed(evt);
            }
        });

        bt_modificar.setIcon(resourceMap.getIcon("bt_modificar.icon")); // NOI18N
        bt_modificar.setText(resourceMap.getString("bt_modificar.text")); // NOI18N
        bt_modificar.setToolTipText(resourceMap.getString("bt_modificar.toolTipText")); // NOI18N
        bt_modificar.setEnabled(false);
        bt_modificar.setName("bt_modificar"); // NOI18N
        bt_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modificarActionPerformed(evt);
            }
        });

        bt_eliminar.setIcon(resourceMap.getIcon("bt_eliminar.icon")); // NOI18N
        bt_eliminar.setText(resourceMap.getString("bt_eliminar.text")); // NOI18N
        bt_eliminar.setToolTipText(resourceMap.getString("bt_eliminar.toolTipText")); // NOI18N
        bt_eliminar.setEnabled(false);
        bt_eliminar.setName("bt_eliminar"); // NOI18N
        bt_eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_eliminarActionPerformed(evt);
            }
        });

        bt_limpiar.setIcon(resourceMap.getIcon("bt_limpiar.icon")); // NOI18N
        bt_limpiar.setText(resourceMap.getString("bt_limpiar.text")); // NOI18N
        bt_limpiar.setToolTipText(resourceMap.getString("bt_limpiar.toolTipText")); // NOI18N
        bt_limpiar.setName("bt_limpiar"); // NOI18N
        bt_limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout editarLayout = new javax.swing.GroupLayout(editar);
        editar.setLayout(editarLayout);
        editarLayout.setHorizontalGroup(
            editarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(bt_eliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
            .addComponent(bt_limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
            .addComponent(bt_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
            .addComponent(bt_guardar, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
        );
        editarLayout.setVerticalGroup(
            editarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editarLayout.createSequentialGroup()
                .addComponent(bt_guardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_modificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_eliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_limpiar)
                .addContainerGap(43, Short.MAX_VALUE))
        );

        tabla.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("tabla.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("tabla.border.titleFont"), resourceMap.getColor("tabla.border.titleColor"))); // NOI18N
        tabla.setFocusable(false);
        tabla.setIcon(resourceMap.getIcon("tabla.icon")); // NOI18N
        tabla.setModo(2);
        tabla.setName("tabla"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        dtm.addColumn("Código");
        dtm.addColumn("Cédula");
        dtm.addColumn("Nombre");
        dtm.addColumn("Cargo");
        dtm.addColumn("e-mail");
        tablaUsuarios.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tablaUsuarios.setEnabled(false);
        tablaUsuarios.setName("tablaUsuarios"); // NOI18N
        jScrollPane1.setViewportView(tablaUsuarios);

        javax.swing.GroupLayout tablaLayout = new javax.swing.GroupLayout(tabla);
        tabla.setLayout(tablaLayout);
        tablaLayout.setHorizontalGroup(
            tablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
        );
        tablaLayout.setVerticalGroup(
            tablaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
        );

        jcMousePanel1.setIcon(resourceMap.getIcon("jcMousePanel1.icon")); // NOI18N
        jcMousePanel1.setName("jcMousePanel1"); // NOI18N

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 414, Short.MAX_VALUE)
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 53, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout pisoUsuarioLayout = new javax.swing.GroupLayout(pisoUsuario);
        pisoUsuario.setLayout(pisoUsuarioLayout);
        pisoUsuarioLayout.setHorizontalGroup(
            pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pisoUsuarioLayout.createSequentialGroup()
                .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pisoUsuarioLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pisoUsuarioLayout.createSequentialGroup()
                                .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cb_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tx_buscar, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                                    .addComponent(jLabel2)))
                            .addGroup(pisoUsuarioLayout.createSequentialGroup()
                                .addComponent(gestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pisoUsuarioLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                                        .addComponent(bt_buscar))
                                    .addGroup(pisoUsuarioLayout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addComponent(editar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tabla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pisoUsuarioLayout.createSequentialGroup()
                        .addGap(211, 211, 211)
                        .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        pisoUsuarioLayout.setVerticalGroup(
            pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pisoUsuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pisoUsuarioLayout.createSequentialGroup()
                        .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tx_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cb_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pisoUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pisoUsuarioLayout.createSequentialGroup()
                                .addComponent(bt_buscar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(editar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(gestion, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(tabla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        gestion.getAccessibleContext().setAccessibleName(resourceMap.getString("Gestion.AccessibleContext.accessibleName")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pisoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_eliminarActionPerformed
        jd_eliminar.setSize(350, 150);
        jd_eliminar.setLocation(350, 300);
        jd_eliminar.setVisible(true);
        // TODO add your handling code here:
}//GEN-LAST:event_bt_eliminarActionPerformed

    private void bt_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_modificarActionPerformed
        try {
            if(tx_codigo.getText().trim().equals("") || tx_cedula.getText().trim().equals("") || tx_nombre.getText().trim().equals("")   || tx_clave.getText().trim().equals("") || tx_email.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Asegurece de llear todos los campos.");
            }
            boolean e = ControlValidacion.validaEmail(tx_email);
            boolean t = ControlValidacion.validaNumero(tx_clave, 11);
            boolean c = ControlValidacion.validaNumero(tx_cedula, 45);
            if(e && t && c){
                Usuario usu = new Usuario();
                usu.setCodigo(tx_codigo.getText());
                usu.setCedula(tx_cedula.getText());
                usu.setNombre(tx_nombre.getText());
                usu.setCargo(cb_cargo.getSelectedItem().toString());
                usu.setClave(tx_clave.getText());
                usu.setEmail(tx_email.getText());
                ControlUsuario.ModificarUsuario(usu,tx_codigo.getText());
                limpiar();
                listarUsuario();
                JOptionPane.showMessageDialog(null,"Usuario modificado con exito!.");
            } else{
                e = ControlValidacion.validaEmail(tx_email);
                t = ControlValidacion.validaNumero(tx_clave, 11);
                c = ControlValidacion.validaNumero(tx_cedula, 15);
                JOptionPane.showMessageDialog(null,"digite bien los datos");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }        // TODO add your handling code here:
}//GEN-LAST:event_bt_modificarActionPerformed

    private void bt_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_buscarActionPerformed
        buscar();
    }//GEN-LAST:event_bt_buscarActionPerformed

    private void bt_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_aceptarActionPerformed
try {
            ControlUsuario.EliminarUsuario(tx_codigo.getText());
            limpiar();
            listarUsuario();

        } catch (SQLException ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
      jd_eliminar.setVisible(false);
          JOptionPane.showMessageDialog(null,"Usuario eliminado con exito!.");        // TODO add your handling code here:
    }//GEN-LAST:event_bt_aceptarActionPerformed

    private void bt_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelarActionPerformed
jd_eliminar.setVisible(false);        // TODO add your handling code here:
    }//GEN-LAST:event_bt_cancelarActionPerformed

    private void tx_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_buscarActionPerformed
        this.buscar();
    }//GEN-LAST:event_tx_buscarActionPerformed

    private void bt_limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limpiarActionPerformed
        limpiar();
    }//GEN-LAST:event_bt_limpiarActionPerformed

    private void bt_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_guardarActionPerformed
       guardar();
        // TODO add your handling code here:
}//GEN-LAST:event_bt_guardarActionPerformed

    private void tx_emailFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_emailFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_tx_emailFocusLost

    private void tx_nombreFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_nombreFocusLost
        tx_nombre.setText(ControlValidacion.convertirMayuscula(tx_nombre.getText()));        // TODO add your handling code here:
}//GEN-LAST:event_tx_nombreFocusLost

    private void tx_nombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_nombreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tx_nombreActionPerformed
    private void tablaUsuariosMouseEntered(java.awt.event.MouseEvent evt) {
        tablaUsuarios.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
public void limpiar(){
        tx_cedula.setText("");
        tx_nombre.setText("");
        tx_clave.setText("");
        tx_reclave.setText("");
        tx_email.setText("");
        tx_buscar.setText("");
        cb_buscar.setSelectedIndex(0);
        bt_modificar.setEnabled(false);
        bt_eliminar.setEnabled(false);
        bt_guardar.setEnabled(true);
        listarUsuario();
}

public void guardar(){
     try {
            if(tx_codigo.getText().trim().equals("") || tx_cedula.getText().trim().equals("") || tx_nombre.getText().trim().equals("") || tx_email.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Asegurece de llear todos los campos.");
            }

            boolean e = ControlValidacion.validaEmail(tx_email);
            
            boolean c = ControlValidacion.validaNumero(tx_cedula, 45);

            if(e  && c){
                Usuario usu = new Usuario();
                usu.setCodigo(tx_codigo.getText());
                usu.setCedula(tx_cedula.getText());
                usu.setNombre(tx_nombre.getText());
                usu.setCargo(cb_cargo.getSelectedItem().toString());
                usu.setEmail(tx_email.getText());
                if(tx_clave.getText().equals(tx_reclave.getText())){
                    usu.setClave(tx_clave.getText());
                    ControlUsuario.agregarUsuario(usu);
                    listarUsuario();
                    limpiar();
                    JOptionPane.showMessageDialog(null,"Usuario guardado con exito!.");
                }else{
                    JOptionPane.showMessageDialog(null,"Las claves no coinciden");
                    tx_clave.setText("");
                    tx_reclave.setText("");
                }
            }else{
                e = ControlValidacion.validaEmail(tx_email);
                c = ControlValidacion.validaNumero(tx_cedula, 15);
                JOptionPane.showMessageDialog(null,"digite bien los datos");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
}
    public void buscar(){
        String item = cb_buscar.getSelectedItem().toString();
            Usuario usu=new Usuario();
        try {
                if(tx_buscar.getText().trim().equals("")){
                    JOptionPane.showMessageDialog(null,"Por favor digite un criterio de busqueda.");
                }else{
                    if(item.equals("Código")){
                        usu = ControlUsuario.BuscarUsuario(tx_buscar.getText());
                     }else{
                        if(item.equals("Cédula")){
                            usu = ControlUsuario.BuscarUsuarioCed(tx_buscar.getText());
                        }else{
                            usu = ControlUsuario.BuscarUsuarioNom(tx_buscar.getText());
                        }
                    }
                }
            if(usu != null){
                tx_codigo.setText((usu.getCodigo()));
                tx_cedula.setText(usu.getCedula());
                tx_nombre.setText(usu.getNombre());
                tx_clave.setText(usu.getClave());
                tx_email.setText(usu.getEmail());
                bt_modificar.setEnabled(true);
                bt_eliminar.setEnabled(true);
                bt_guardar.setEnabled(false);
                tx_buscar.setText("");
            }else{
                JOptionPane.showMessageDialog(null,"Usuario no encontrado.");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new vistaUsuario().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_aceptar;
    private javax.swing.JButton bt_buscar;
    private javax.swing.JButton bt_cancelar;
    private javax.swing.JButton bt_eliminar;
    private javax.swing.JButton bt_guardar;
    private javax.swing.JButton bt_limpiar;
    private javax.swing.JButton bt_modificar;
    private javax.swing.JComboBox cb_buscar;
    private javax.swing.JComboBox cb_cargo;
    private jcMousePanel.jcMousePanel editar;
    private jcMousePanel.jcMousePanel gestion;
    private jcMousePanel.jcMousePanel imagen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    private javax.swing.JDialog jd_eliminar;
    public static jcMousePanel.jcMousePanel pisoUsuario;
    private jcMousePanel.jcMousePanel tabla;
    private javax.swing.JTable tablaUsuarios;
    private javax.swing.JTextField tx_buscar;
    private javax.swing.JTextField tx_cedula;
    private javax.swing.JPasswordField tx_clave;
    private javax.swing.JTextField tx_codigo;
    private javax.swing.JTextField tx_email;
    private javax.swing.JTextField tx_nombre;
    private javax.swing.JPasswordField tx_reclave;
    // End of variables declaration//GEN-END:variables

}
